<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
$(document).ready(function(){
	
	$.ajax({
		type:"POST",
		url:"hopeSubjectList.do",
		dataType:"json",
		success:function(jsonData){
			$("#grade option").remove();
			var op="<option value=''>--</option>";
			$("#grade").append(op);
				$.each(jsonData.gradeList,function(index, gradelist){
					op="<option value="+gradelist.code_code+">"+gradelist.code_name+"</option>";
				$("#grade").append(op); 					
			});//$.each
		}//success
	});//ajax 학년
	$.ajax({
		type:"POST",
		url:"hopeSubjectList.do",
		dataType:"json",
		success:function(jsonData){
			$("#hopeSubject option").remove();
			var op="<option value=''>--</option>";
			$("#hopeSubject").append(op);
				$.each(jsonData.hopeSubjectList,function(index, hopeSubjectList){
					op="<option value="+hopeSubjectList.code_code+">"+hopeSubjectList.code_name+"</option>";
				$("#hopeSubject").append(op); 					
			});//$.each
		}//success
	});//ajax 과목
	$("#searchBtn").click(function(){
		var grade=$("#grade").val();
		var hopeSubject=$("#hopeSubject").val();
		if($("#grade").val()=="" && $("#hopeSubject").val()==""){
		alert("검색할 정보를 입력하세요");
		return false;
			}else{
			location.href="searchLesson.do?grade="+grade+"&hopesubject="+hopeSubject;
		};//if else
	});//$("#searchBtn").click
	$("#totalLessonBoard").click(function(){
		location.href="lessonBoardSerch.do";
	});
	
});//ready
</script>
</head>
<body>
<center>
<h2 align="center">수업 찾기</h2>
<h5 align="left" > 학생이 원하는 수업을 검색하세요.<br><br>
학생은 원하는 수업을 등록할 수 있습니다.</h5><br>
<form id="serchForm" >
<table >
	<tr>
		<td>학년</td><td><select id="grade" name="grade"></select></td>
		<td>과목</td><td><select id="hopeSubject" name="hopeSubject"></select></td>
		
		<td align="right"><input type="button" id="searchBtn" value="검색"> </td>
			<td><input type="button" id="totalLessonBoard" value="전체보기"></td>
	</tr>
</table>

</form>
<table width="600" style="border-width: 0.5mm; table-layout: fixed"  bgcolor="#F8F8F8" >
	<thead >
	<tr bgcolor="#E6E6E6" align="center">
	<td><font size="2">번호</font></td>
	<td><font size="2">제목</font></td>
	<td><font size="2">학년</font></td>
	<td><font size="2">과목</font></td>
	<td><font size="2">작성자</font></td>
	<td><font size="2">연결여부</font></td>
	<td><font size="2">조회수</font></td>
	</tr>
	</thead>
	<tbody id="serchListTbody" align="center">
	<c:forEach items="${requestScope.searchList.list }" var="list">
	<tr>
	<td><font size="2">${list.lessonno }</font></td>
	<td><a href="showLessonBoardInfo.do?lessonno=${list.lessonno }&studentid=${list.studentid}"><font size="2">${list.title }</font></a></td>
	<td><font size="2">${list.grade }</font></td>
	<td><font size="2">${list.hopesubject }</font></td>
	<td><font size="2">${list.name }</font></td>
	<td><font size="2">${list.connectstate }</font></td>
	<td><font size="2">${list.hits }</font></td>
	</tr>
	</c:forEach>
	</tbody> 
</table>
<br>

<c:if test="${requestScope.searchList.pagingBean.previousPageGroup }">
<a href="searchLesson.do?pageNo=${requestScope.searchList.pagingBean.startPageOfPageGroup-1}&grade=${grade}&hopesubject=${hopesubject }">◀</a>
</c:if>
&nbsp;&nbsp;
<c:forEach var="i" 
begin="${requestScope.searchList.pagingBean.startPageOfPageGroup}"
end="${requestScope.searchList.pagingBean.endPageOfPageGroup}">
	<c:choose>
		<c:when test="${requestScope.searchList.pagingBean.nowPage!=i}">
		<a href="searchLesson.do?pageNo=${i}&grade=${grade}&hopesubject=${hopesubject }">${i}</a>
		</c:when>
		<c:otherwise>
		${i}
		</c:otherwise>
	</c:choose>
</c:forEach>
&nbsp;&nbsp;
<c:if test="${requestScope.searchList.pagingBean.nextPageGroup}">
<a href="searchLesson.do?pageNo=${requestScope.searchList.pagingBean.endPageOfPageGroup+1}&grade=${grade}&hopesubject=${hopesubject }">▶</a>
</c:if>
<br>
<br>
<c:if test="${sessionScope.mvo.membertype=='s'}">
<a href="writeLessonPage.do"><input type="button" value="글쓰기"></a>
</c:if>
</center>
</body>
</html>